//
//  FifthViewController.m
//  XDCommonApp
//
//  Created by XD-XY on 2/12/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "FifthViewController.h"
#import "XDHeader.h"
#import "XDTools.h"
#import "UIButton+Category.h"
#import "UIImageView+WebCache.h"

#define image_tag 10000

@interface FifthViewController ()

@end

@implementation FifthViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    DDLOG_CURRENT_METHOD;
    [pageView openTimerTask];
}

-(void)viewWillDisappear:(BOOL)animated
{
    DDLOG_CURRENT_METHOD;
    [pageView closeTimerTask];
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.leftBtn.hidden =YES;
    self.titleLabel.text = FIFTHVIEWTITLETEXT;
    
    /*图片轮播*/
    pageView = [[XYScrollView alloc] initPageScrollView:CGRectMake(0, 0, 320, 100) pageControllerFrame:CGRectMake(120,50, 100, 10) backgroudImage:nil pageNumber:PAGESCROLLVIEWNUMBER];
    //如果有图片点击事件，就设置代理，没有则不设置
    pageView.delegate = self;
    if (ISREQUSETIMAGE){
        //图片来源于网络
        NSArray * imageUrlArray = @[@"http://app.lgmi.com/upload/1.png",
                                    @"http://app.lgmi.com/upload/2.png",
                                    @"http://app.lgmi.com/upload/4.png",
                                    @"http://app.lgmi.com/upload/7.png",
                                    ];
        [pageView setTheImageUrlArray:imageUrlArray andplaceholderImage:PAGEDEFAULTIAMGE];
    }else{
        //图片来源于本地
        NSArray * imageArray = [[NSArray alloc] initWithObjects:PAGESCROLLVIEWIMAGE1,PAGESCROLLVIEWIMAGE2,PAGESCROLLVIEWIMAGE3,PAGESCROLLVIEWIMAGE4,nil];
        [pageView setTheImageArray:imageArray];
    }
    [self.contentView addSubview:pageView];
    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 200, 300, 100)];
    [imageView setImageWithURL:[NSURL URLWithString:@"http://app.lgmi.com/upload/1.png"] placeholderImage:[UIImage imageNamed:@"Icon"]];
    [self.contentView addSubview:imageView];
    UIImageView * imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(10, height_y(imageView)+10, 300, 100)];
    [imageView2 setImageWithURL:[NSURL URLWithString:@"http://app.lgmi.com/upload/2.png47"] placeholderImage:nil];
    [self.contentView addSubview:imageView2];
}

//清楚缓存
-(void)clearClick
{
    [[SDImageCache sharedImageCache] clearDisk];
    [[SDImageCache sharedImageCache] clearMemory];
}

//指示器提示框
-(void)btnClick:(UIButton *)sender
{
    DDLOG_CURRENT_METHOD;
    if (sender.tag==1){
        [XDTools showTips:@"操作成功" toView:self.contentView];
    }else if (sender.tag ==2){
        [XDTools showProgress:self.contentView];
    }else if (sender.tag ==3){
        [XDTools showProgress:self.contentView showText:@"正在加载..."];
    }else if (sender.tag ==4){
        
    }else if (sender.tag ==5){
        
    }
}

-(void)getData
{
    NSDictionary *dict = @{@"module":@"1",
                           @"page":@"1",
                           };
    
    __weak ASIHTTPRequest *request = [XDTools getRequestWithDict:dict API:API_GetInfoList];
    [request setCompletionBlock:^{
        NSString *responseString = [request responseString];
        NSMutableString *muString = [[NSMutableString alloc] initWithString:responseString];
        [muString replaceOccurrencesOfString:@"\r" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, muString.length)];
        [muString replaceOccurrencesOfString:@"\n" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, muString.length)];
        [muString replaceOccurrencesOfString:@"\t" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, muString.length)];
        NSDictionary *tempDic = [XDTools  JSonFromString:muString];
        
    }];
    
    [request setFailedBlock:^{
        
    }];
    [request startAsynchronous];
    
}

//这个是XYScrollView中的代理方法，主要的功能可以实现里面每个imageview的点击事件的
-(void)gestureClick:(UITapGestureRecognizer *)sender
{
    DDLOG_CURRENT_METHOD;
    UIImageView * imageView =(UIImageView *)[pageView.myScrollView viewWithTag:sender.view.tag];
    
    //这里就写跳到下一的代码....imageView.tag-image_tag
    DDLOG(@"imageView.tag = %d",imageView.tag);
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

@end
